﻿Imports System
Imports System.Diagnostics.CodeAnalysis
Imports System.Globalization
Imports System.Workflow.ComponentModel

Namespace System.Workflow.Activities.Rules
    Public Class RuleExecution
        ' Methods
        <SuppressMessage("Microsoft.Naming", "CA1720:AvoidTypeNamesInParameters", MessageId:="1#")> _
        Public Sub New(ByVal validation As RuleValidation, ByVal thisObject As Object)
            If (validation Is Nothing) Then
                Throw New ArgumentNullException("validation")
            End If
            If (thisObject Is Nothing) Then
                Throw New ArgumentNullException("thisObject")
            End If
            If (Not validation.ThisType Is thisObject.GetType) Then
                Throw New InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Messages.ValidationMismatch, New Object() { RuleDecompiler.DecompileType(validation.ThisType), RuleDecompiler.DecompileType(thisObject.GetType) }))
            End If
            Me.validation = validation
            Me.activity = [TryCast](thisObject,Activity)
            Me.thisObject = thisObject
            Me.thisLiteralResult = New RuleLiteralResult(thisObject)
        End Sub

        <SuppressMessage("Microsoft.Naming", "CA1720:AvoidTypeNamesInParameters", MessageId:="1#")> _
        Public Sub New(ByVal validation As RuleValidation, ByVal thisObject As Object, ByVal activityExecutionContext As ActivityExecutionContext)
            Me.New(validation, thisObject)
            Me.activityExecutionContext = activityExecutionContext
        End Sub


        ' Properties
        Public ReadOnly Property Activity As Activity
            Get
                If (Me.activity Is Nothing) Then
                    Throw New InvalidOperationException(Messages.NoActivity)
                End If
                Return Me.activity
            End Get
        End Property

        Public ReadOnly Property ActivityExecutionContext As ActivityExecutionContext
            Get
                Return Me.activityExecutionContext
            End Get
        End Property

        Public Property Halted As Boolean
            Get
                Return Me.halted
            End Get
            Set(ByVal value As Boolean)
                Me.halted = value
            End Set
        End Property

        Friend ReadOnly Property ThisLiteralResult As RuleLiteralResult
            Get
                Return Me.thisLiteralResult
            End Get
        End Property

        Public ReadOnly Property ThisObject As Object
            Get
                Return Me.thisObject
            End Get
        End Property

        Public Property Validation As RuleValidation
            Get
                Return Me.validation
            End Get
            Set(ByVal value As RuleValidation)
                If (value Is Nothing) Then
                    Throw New ArgumentNullException("value")
                End If
                Me.validation = value
            End Set
        End Property


        ' Fields
        Private activity As Activity
        Private activityExecutionContext As ActivityExecutionContext
        Private halted As Boolean
        Private thisLiteralResult As RuleLiteralResult
        Private thisObject As Object
        Private validation As RuleValidation
    End Class
End Namespace

